package com.example.idachuappone.index.item;

import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.idachuappone.BaseActivity;
import com.example.idachuappone.R;
import com.example.idachuappone.index.entity.FamilyFeastImgs;
import com.example.idachuappone.utils.BitmapUtilHelper;
import com.lidroid.xutils.BitmapUtils;
import java.util.ArrayList;
import java.util.List;

public class FamilyFeastTwoImageVpActivity extends BaseActivity implements OnClickListener {
    PagerAdapter adapter;
    private Button btn_back;
    private BitmapUtils bu;
    private int index;
    private List<FamilyFeastImgs> list;
    private LinearLayout ll_back;
    private List<View> pageViews;
    private TextView tv_number;
    private TextView tv_title;
    private ViewPager viewPager;

    private final class AdPageChangeListener implements OnPageChangeListener {
        private AdPageChangeListener() {
        }

        public void onPageScrollStateChanged(int arg0) {
        }

        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        public void onPageSelected(int arg0) {
            FamilyFeastTwoImageVpActivity.this.tv_number.setText((arg0 + 1) + "/" + FamilyFeastTwoImageVpActivity.this.list.size());
            FamilyFeastTwoImageVpActivity.this.tv_title.setText(((FamilyFeastImgs) FamilyFeastTwoImageVpActivity.this.list.get(arg0)).getName());
        }
    }

    public FamilyFeastTwoImageVpActivity() {
        this.adapter = new PagerAdapter() {
            public void destroyItem(ViewGroup container, int position, Object object) {
                ((ViewPager) container).removeView((View) FamilyFeastTwoImageVpActivity.this.pageViews.get(position));
            }

            public boolean isViewFromObject(View arg0, Object arg1) {
                return arg0 == arg1;
            }

            public Object instantiateItem(ViewGroup container, int position) {
                ((ViewPager) container).addView((View) FamilyFeastTwoImageVpActivity.this.pageViews.get(position));
                ((View) FamilyFeastTwoImageVpActivity.this.pageViews.get(position)).setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                    }
                });
                return FamilyFeastTwoImageVpActivity.this.pageViews.get(position);
            }

            public int getCount() {
                return FamilyFeastTwoImageVpActivity.this.pageViews == null ? 0 : FamilyFeastTwoImageVpActivity.this.pageViews.size();
            }
        };
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment_greens_list);
        this.bu = BitmapUtilHelper.createBitmapUtil(this);
        this.list = (List) getIntent().getSerializableExtra("list");
        this.index = getIntent().getIntExtra("index", 0);
        this.viewPager = (ViewPager) findViewById(R.id.viewpager);
        this.viewPager.setOnPageChangeListener(new AdPageChangeListener());
        this.ll_back = (LinearLayout) findViewById(R.id.ll_back);
        this.ll_back.setOnClickListener(this);
        this.btn_back = (Button) findViewById(R.id.btn_back);
        this.btn_back.setOnClickListener(this);
        this.tv_number = (TextView) findViewById(R.id.tv_number);
        this.tv_title = (TextView) findViewById(R.id.tv_title);
        initPageAdapter();
        this.viewPager.setAdapter(this.adapter);
        this.viewPager.setCurrentItem(this.index);
        this.tv_number.setText(new StringBuilder(String.valueOf(this.index + 1)).append("/").append(this.list.size()).toString());
        this.tv_title.setText(((FamilyFeastImgs) this.list.get(this.index)).getName());
    }

    private void initPageAdapter() {
        this.pageViews = new ArrayList();
        for (int i = 0; i < this.list.size(); i++) {
            View view = LinearLayout.inflate(this, R.layout.simple_comment_greens_item, null);
            this.bu.display((ImageView) view.findViewById(R.id.img), ((FamilyFeastImgs) this.list.get(i)).getImg());
            this.pageViews.add(view);
        }
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_back /*2131165198*/:
            case R.id.ll_back /*2131165223*/:
                finish();
            default:
        }
    }
}
